package com.itlong.cloud.rabbitmq.config;

import com.itlong.cloud.constants.RabbitMQConstant;
import com.itlong.cloud.utils.rabbitMQ.BaseConfig;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * <desc>
 *      设备服务消息队列配置。
 * </desc>
 *
 * @createDate 2017/08/29
 */
@Configuration
public class RabbitConfig extends BaseConfig {

    //声明队列，true表示持久化该队列
    @Bean
    public Queue queue1() {
        return new Queue(RabbitMQConstant.RABBITMQ_EQUIP_SAVE_EQUIP_INFO_QUEUE1, true);
    }

    @Bean
    public Queue queue2() {
        return new Queue(RabbitMQConstant.RABBITMQ_EQUIP_SAVE_EQUIP_INFO_QUEUE2, true);
    }



    //添加或更新sip
    @Bean
    public Queue saveOrUpdateSip() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_SAVE_OR_UPDATE_SIP_QUEUE, true, false, false, map);
        return queue;
    }

    //运营启用云对讲时，同步项目中云对讲设备的Sip
    @Bean
    public Queue syncEquipSipWhenEnableCloud() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_SYNC_EQUIP_SIP_WHEN_ENABLE_CLOUD_QUEUE, true, false, false, map);
        return queue;
    }

    //更新APP用户设备列表缓存队列
    @Bean
    public Queue updateAppUserInfoDevice(){
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        return new Queue(RabbitMQConstant.RABBITMQ_EQUIP_APP_USER_INFO_DEVICE_UPDATE_QUEUE,true,false,false,map);
    }


    //住户设备权限刷新队列
    @Bean
    public Queue houserHoldDeviceAuthRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_USER_SAVE_DEVICE_AUTH_INFO_QUEUE, true, false, false, map);
        return queue;
    }

    //根据地址去除住户其他类别设备权限队列
    @Bean
    public Queue houserHoldRemoveAuthByAddrRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_USER_REMOVE_DEVICE_AUTH_BY_ADDR_QUEUE, true, false, false, map);
        return queue;
    }



    //处理一卡通上传的住户设备权限数据
    @Bean
    public Queue handleSmartCardPushAuth() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_DOCKWITHSMARTCARD_HANDLE_DEVICEAUTH_QUEUE, true, false, false, map);
        return queue;
    }

    //处理用户呼梯预约状态
    @Bean
    public Queue handleCallElevatorOperateStatusRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_CALL_ELEVATOR_OPERATE_STATUS_QUEUE, true, false, false, map);
        return queue;
    }

    //处理电梯楼层范围更改影响的物业临时用户电梯楼层权限队列
    @Bean
    public Queue changeUserElevatorFloorAuthRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_CHANGE_USER_ELEVATOR_FLOOR_AUTH_QUEUE, true, false, false, map);
        return queue;
    }
    //运营禁用人脸识别配置时，项目中云对讲设备的人脸识别状态改为0的队列
    @Bean
    public Queue cloudTalkEquipModifyFace() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_CLOUD_TALK_EQUIP_MODIFY_FACE_QUEUE, true, false, false, map);
        return queue;
    }

    //平板用户权限信息变更指令推送队列
    @Bean
    public Queue padUserAuthChangePushRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_PAD_USER_AUTH_CHANGE_PUSH_QUEUE, true, false, false, map);
        return queue;
    }

    //C#人脸识别用户权限信息变更指令推送队列
    @Bean
    public Queue smartCardFaceUserAuthChangePushRabbit() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_SMARTCARD_FACE_USER_AUTH_CHANGE_PUSH_QUEUE, true, false, false, map);
        return queue;
    }

    //云电梯业务指令交互器
    @Bean
    TopicExchange topicCloudElevatorExchange(){
        return new TopicExchange(RabbitMQConstant.RABBITMQ_CLOUD_ELEVATOR_CHANGE_BUSINESS_EXCHANGE);
    }

    //声明云电梯设备同步业务指令处理队列，true表示持久化该队列
    @Bean
    public Queue handleCloudElevatorChangeBusinessQueue() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_HANDLE_CLOUD_ELEVATOR_CHANGE_BUSINESS_QUEUE,true, false, false, map);
        return queue;
    }

    //绑定云电梯设备同步业务指令处理队列和路由Key
    @Bean
    Binding  cloudElevatorChangeBusinessBinding() {
        return BindingBuilder.bind(handleCloudElevatorChangeBusinessQueue()).to(topicCloudElevatorExchange()).with(RabbitMQConstant.RABBITMQ_CLOUD_ELEVATOR_CHANGE_BUSINESS_ROUTING_KEY);
    }

    //云门禁业务指令交互器
    @Bean
    TopicExchange topicCloudEntranceExchange(){
        return new TopicExchange(RabbitMQConstant.RABBITMQ_CLOUD_ENTRANCE_CHANGE_BUSINESS_EXCHANGE);
    }

    //声明云门禁设备同步业务指令处理队列，true表示持久化该队列
    @Bean
    public Queue handleCloudEntranceChangeBusinessQueue() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_HANDLE_CLOUD_ENTRANCE_CHANGE_BUSINESS_QUEUE,true, false, false, map);
        return queue;
    }

    //*************************************云对讲设备同步业务指令相关配置***********************************************

    //声明交互器
    @Bean
    DirectExchange smartCommunityOrdersDirectExchange() {
        return new DirectExchange(RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_EXCHANGE);
    }

    //声明云对讲设备同步业务指令处理队列，true表示持久化该队列
    @Bean
    public Queue handleSmartCommunityOredersQueue() {
        Map<String, Object> map = new HashMap();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_HANDLE_SMART_COMMUNITY_ORDERS_QUEUE,true, false, false, map);
        return queue;
    }

    //绑定云对讲设备同步业务指令处理队列和路由Key
    @Bean
    Binding  pullDeviceAuthInfoBinding() {
        return BindingBuilder.bind(handleSmartCommunityOredersQueue()).to(smartCommunityOrdersDirectExchange()).with(RabbitMQConstant.RABBITMQ_SMART_COMMUNITY_ORDERS_ROUTING_KEY);
    }

    //绑定云门禁设备同步业务指令处理队列和路由Key
    @Bean
    Binding cloudEntranceChangeBusinessBinding() {
        return BindingBuilder.bind(handleCloudEntranceChangeBusinessQueue()).to(topicCloudEntranceExchange()).with(RabbitMQConstant.RABBITMQ_CLOUD_ENTRANCE_CHANGE_BUSINESS_ROUTING_KEY);
    }

    //绑定
    @Bean
    public Binding padUserAuthChangePushRabbitBinding() {
        return BindingBuilder.bind(padUserAuthChangePushRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_PAD_USER_AUTH_CHANGE_PUSH_KEY);
    }

    //声明交互器
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(RabbitMQConstant.RABBITMQ_EQUIP_EXCHANGE);
    }

    //绑定
    @Bean
    public Binding changeUserElevatorFloorAuthRabbitBinding() {
        return BindingBuilder.bind(changeUserElevatorFloorAuthRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_CHANGE_USER_ELEVATOR_FLOOR_AUTH_KEY);
    }

    //绑定
    @Bean
    public Binding callElevatorOperateStatusBinding() {
        return BindingBuilder.bind(handleCallElevatorOperateStatusRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_CALL_ELEVATOR_OPERATE_STATUS_KEY);
    }

    //绑定
    @Bean
    public Binding binding1() {
        return BindingBuilder.bind(queue1()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_EQUIP_SAVE_EQUIP_INFO_ROUTING_KEY1);
    }

    @Bean
    public Binding binding2() {
        return BindingBuilder.bind(queue2()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_EQUIP_SAVE_EQUIP_INFO_ROUTING_KEY2);
    }


    @Bean
    public Binding updateAppUserInfoDeviceBinding(){
        return BindingBuilder.bind(updateAppUserInfoDevice()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_EQUIP_APP_USER_INFO_DEVICE_UPDATE_KEY);
    }


    @Bean public Binding saveOrUpdateSipBinding() {
        return BindingBuilder.bind(saveOrUpdateSip()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_SAVE_OR_UPDATE_SIP_KEY);
    }


    @Bean Binding houserHoldDeviceAuthbinding() {
        return BindingBuilder.bind(houserHoldDeviceAuthRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_USER_SAVE_DEVICE_AUTH_INFO_ROUTING_KEY);
    }

    @Bean Binding houserHoldRemoveAuthByAddrbinding() {
        return BindingBuilder.bind(houserHoldRemoveAuthByAddrRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_USER_REMOVE_DEVICE_AUTH_BY_ADDR_ROUTING_KEY);
    }

    @Bean Binding handleSmartCardPushAuthbinding() {
        return  BindingBuilder.bind(handleSmartCardPushAuth()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_DOCKWITHSMARTCARD_HANDLE_DEVICEAUTH_ROUTING_KEY);
    }

    @Bean Binding syncEquipSipWhenEnableCloudBinding() {
        return  BindingBuilder.bind(syncEquipSipWhenEnableCloud()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_SYNC_EQUIP_SIP_WHEN_ENABLE_CLOUD_KEY);
    }

    @Bean Binding cloudTalkEquipModifyFaceBinding() {
        return  BindingBuilder.bind(cloudTalkEquipModifyFace()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_CLOUD_TALK_EQUIP_MODIFY_FACE_KEY);
    }

    //C#人脸识别用户权限信息变更指令推送队列绑定
    @Bean
    public Binding smartCardFaceUserAuthChangePushRabbitBinding() {
        return BindingBuilder.bind(smartCardFaceUserAuthChangePushRabbit()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_SMARTCARD_FACE_USER_AUTH_CHANGE_PUSH_KEY);
    }

    public static void main(String[] args) {
    }
}
